home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Kit PC World De Ampliacion De Windows 95
/
Kit PC World de ampliacion de Windows 95.iso
/
internet
/
sweeper
/
samples
/
olecon~1
/
include
/
ctrlobj.h
< prev
next >
Wrap
Text File
|
1995-11-29
|
20KB
|
452 lines
//=--------------------------------------------------------------------------=
// ControlObject.H
//=--------------------------------------------------------------------------=
// Copyright 1995 Microsoft Corporation. All Rights Reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//=--------------------------------------------------------------------------=
//
// class declaration for the COleControl object
//
#ifndef _CONTROLOBJECT_H_
// we need the automation object and ctlole.h
//
#include "AutoObj.H"
#include <olectl.h>
// forward declaration
//
class COleControl;
//=--------------------------------------------------------------------------=
// Misc Helper Functions
//=--------------------------------------------------------------------------=
//
// given an Unknown pointer, get the COleControl * for it. used typically
// in property page code.
//
COleControl *ControlFromUnknown(IUnknown *);
//=--------------------------------------------------------------------------=
// Misc Constants
//=--------------------------------------------------------------------------=
// maximum number of arguments that can be sent to FireEvent()
//
#define MAX_ARGS 32
// for the types of sinks that the COleControl class has. you shouldn't ever
// need to use these
//
#define SINK_TYPE_EVENT 0
#define SINK_TYPE_PROPNOTIFY 1
// superclass window support. you can pass this in to DoSuperClassPaint
//
#define DRAW_SENDERASEBACKGROUND 1
//=--------------------------------------------------------------------------=
// Various Hosts don't handle OLEIVERB_PROPERTIES correctly, so we can't use
// that as our Properties verb number. Instead, we're going to define
// CTLIVERB_PROPERTIES as 1, and return that one in IOleObject::EnumVerbs,
// but we'll still handle OLEIVERB_PROPERTIES correctly in DoVerb.
//
#define CTLIVERB_PROPERTIES 1
//=--------------------------------------------------------------------------=
// this structure is like the OLEVERB structure, except that it has a resource ID
// instead of a string for the verb's name. better support for localization.
//
typedef struct tagVERBINFO {
LONG lVerb; // verb id
ULONG idVerbName; // resource ID of verb name
DWORD fuFlags; // verb flags
DWORD grfAttribs; // Specifies some combination of the verb attributes in the OLEVERBATTRIB enumeration.
} VERBINFO;
// describes an event
//
typedef struct tagEVENTINFO {
DISPID dispid; // dispid of the event
int cParameters; // number of arguments to the event
VARTYPE *rgTypes; // type of each argument
} EVENTINFO;
//=--------------------------------------------------------------------------=
// CONTROLOBJECTINFO
//=--------------------------------------------------------------------------=
// for each control you wish to expose to the programmer/user, you need to
// declare and define one of the following structures. the first part should
// follow the rules of the AUTOMATIONOBJECTINFO structure. it's pretty hard,
// however, to imagine a scenario where the control isn't CoCreatable ...
// once this structre is declared/defined, an entry should be put in the
// global g_ObjectInfo table.
//
typedef struct tagCONTROLOBJECT {
AUTOMATIONOBJECTINFO AutomationInfo; // automation and creation information
const IID *piidEvents; // IID of primary event interface
DWORD dwControlFlags; // control flags
WORD wToolboxId; // resource ID of Toolbox Bitmap
LPSTR szWndClass; // name of window control class
VARIANT_BOOL fWindowClassRegistered; // has the window class been registered yet?
WORD cPropPages; // number of property pages
const GUID **rgPropPageGuids; // array of the property page GUIDs
WORD cCustomVerbs; // number of custom verbs
VERBINFO *rgCustomVerbs; // description of custom verbs
WNDPROC pfnSubClass; // for subclassed controls.
} CONTROLOBJECTINFO;
#ifndef INITOBJECTS
#define DEFINE_CONTROLOBJECT(name, clsid, progid, fn, ver, riid, pszh, piide, dwcf, w, szwc, cpp, rgppg, ccv, rgcv) \
extern CONTROLOBJECTINFO name##Control \
#else
#define DEFINE_CONTROLOBJECT(name, clsid, progid, fn, ver, riid, pszh, piide, dwcf, w, szwc, cpp, rgppg, ccv, rgcv) \
CONTROLOBJECTINFO name##Control = { { {clsid, progid, fn}, ver, riid, pszh, NULL, 0}, piide, dwcf, w, szwc, FALSE, cpp, rgppg, ccv, rgcv, NULL } \
#endif // !INITOBJECTS
#define OLEMISCFLAGSOFCONTROL(index) ((CONTROLOBJECTINFO *)(g_ObjectInfo[index].pInfo))->dwControlFlags
#define EVENTIIDOFCONTROL(index) (*(((CONTROLOBJECTINFO *)(g_ObjectInfo[index].pInfo))->piidEvents))
#define WNDCLASSNAMEOFCONTROL(index) ((CONTROLOBJECTINFO *)(g_ObjectInfo[index].pInfo))->szWndClass
#define CPROPPAGESOFCONTROL(index) ((CONTROLOBJECTINFO *)(g_ObjectInfo[index].pInfo))->cPropPages
#define PPROPPAGESOFCONTROL(index) ((CONTROLOBJECTINFO *)(g_ObjectInfo[index].pInfo))->rgPropPageGuids
#define CCUSTOMVERBSOFCONTROL(index) ((CONTROLOBJECTINFO *)(g_ObjectInfo[index].pInfo))->cCustomVerbs
#define CUSTOMVERBSOFCONTROL(index) ((CONTROLOBJECTINFO *)(g_ObjectInfo[index].pInfo))->rgCustomVerbs
#define BITMAPIDOFCONTROL(index) ((CONTROLOBJECTINFO *)(g_ObjectInfo[index].pInfo))->wToolboxId
#define CTLWNDCLASSREGISTERED(index) ((CONTROLOBJECTINFO *)(g_ObjectInfo[index].pInfo))->fWindowClassRegistered
#define SUBCLASSWNDPROCOFCONTROL(index)((CONTROLOBJECTINFO *)(g_ObjectInfo[index].pInfo))->pfnSubClass
//=--------------------------------------------------------------------------=
// COleControl
//=--------------------------------------------------------------------------=
// the mother of all C++ objects
//
class COleControl : public CAutomationObject,
public IOleObject, public IOleControl,
public IOleInPlaceObject, public IOleInPlaceActiveObject,
public IViewObject2, public IPersistPropertyBag,
public IPersistStreamInit, public IPersistStorage,
public IConnectionPointContainer, public ISpecifyPropertyPages,
public IProvideClassInfo
{
public:
// IUnknown methods -- there are required since we inherit from variuos
// people who themselves inherit from IUnknown. just delegate to controlling
// unknown
//
DECLARE_STANDARD_UNKNOWN();
//=--------------------------------------------------------------------------=
// IPersist methods. used by IPersistStream and IPersistStorage
//
STDMETHOD(GetClassID)(THIS_ LPCLSID lpClassID);
// IPersistStreamInit methods
//
STDMETHOD(IsDirty)(THIS);
STDMETHOD(Load)(LPSTREAM pStm);
STDMETHOD(Save)(LPSTREAM pStm, BOOL fClearDirty);
STDMETHOD(GetSizeMax)(ULARGE_INTEGER FAR* pcbSize);
STDMETHOD(InitNew)();
// IPersistStorage
//
STDMETHOD(InitNew)(IStorage *pStg);
STDMETHOD(Load)(IStorage *pStg);
STDMETHOD(Save)(IStorage *pStgSave, BOOL fSameAsLoad);
STDMETHOD(SaveCompleted)(IStorage *pStgNew);
STDMETHOD(HandsOffStorage)(void);
// IPersistPropertyBag
//
STDMETHOD(Load)(LPPROPERTYBAG pPropBag, LPERRORLOG pErrorLog);
STDMETHOD(Save)(LPPROPERTYBAG pPropBag, BOOL fClearDirty,
BOOL fSaveAllProperties);
// IOleControl methods
//
STDMETHOD(GetControlInfo)(LPCONTROLINFO pCI);
STDMETHOD(OnMnemonic)(LPMSG pMsg);
STDMETHOD(OnAmbientPropertyChange)(DISPID dispid);
STDMETHOD(FreezeEvents)(BOOL bFreeze);
// IOleObject methods
//
STDMETHOD(SetClientSite)(IOleClientSite *pClientSite);
STDMETHOD(GetClientSite)(IOleClientSite * *ppClientSite);
STDMETHOD(SetHostNames)(LPCOLESTR szContainerApp, LPCOLESTR szContainerObj);
STDMETHOD(Close)(DWORD dwSaveOption);
STDMETHOD(SetMoniker)(DWORD dwWhichMoniker, IMoniker *pmk);
STDMETHOD(GetMoniker)(DWORD dwAssign, DWORD dwWhichMoniker, IMoniker * *ppmk);
STDMETHOD(InitFromData)(IDataObject *pDataObject, BOOL fCreation, DWORD dwReserved);
STDMETHOD(GetClipboardData)(DWORD dwReserved, IDataObject * *ppDataObject);
STDMETHOD(DoVerb)(LONG iVerb, LPMSG lpmsg, IOleClientSite *pActiveSite, LONG lindex,
HWND hwndParent, LPCRECT lprcPosRect);
STDMETHOD(EnumVerbs)(IEnumOLEVERB * *ppEnumOleVerb);
STDMETHOD(Update)(void);
STDMETHOD(IsUpToDate)(void);
STDMETHOD(GetUserClassID)(CLSID *pClsid);
STDMETHOD(GetUserType)(DWORD dwFormOfType, LPOLESTR *pszUserType);
STDMETHOD(SetExtent)(DWORD dwDrawAspect,SIZEL *psizel);
STDMETHOD(GetExtent)(DWORD dwDrawAspect, SIZEL *psizel);
STDMETHOD(Advise)(IAdviseSink *pAdvSink, DWORD *pdwConnection);
STDMETHOD(Unadvise)(DWORD dwConnection);
STDMETHOD(EnumAdvise)(IEnumSTATDATA * *ppenumAdvise);
STDMETHOD(GetMiscStatus)(DWORD dwAspect, DWORD *pdwStatus);
STDMETHOD(SetColorScheme)(LOGPALETTE *pLogpal);
// IOleWindow. required for IOleInPlaceObject and IOleInPlaceActiveObject
//
STDMETHOD(GetWindow)(HWND *phwnd);
STDMETHOD(ContextSensitiveHelp)(BOOL fEnterMode);
// IOleInPlaceObject
//
STDMETHOD(InPlaceDeactivate)(void);
STDMETHOD(UIDeactivate)(void);
STDMETHOD(SetObjectRects)(LPCRECT lprcPosRect,LPCRECT lprcClipRect) ;
STDMETHOD(ReactivateAndUndo)(void);
// IOleInPlaceActiveObject
//
STDMETHOD(TranslateAccelerator)(LPMSG lpmsg);
STDMETHOD(OnFrameWindowActivate)(BOOL fActivate);
STDMETHOD(OnDocWindowActivate)(BOOL fActivate);
STDMETHOD(ResizeBorder)(LPCRECT prcBorder,
IOleInPlaceUIWindow *pUIWindow,
BOOL fFrameWindow);
STDMETHOD(EnableModeless)(BOOL fEnable);
// IViewObject2
//
STDMETHOD(Draw)(DWORD dwDrawAspect, LONG lindex, void *pvAspect,
DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw,
LPCRECTL lprcBounds, LPCRECTL lprcWBounds,
BOOL ( __stdcall *pfnContinue )(DWORD dwContinue),
DWORD dwContinue);
STDMETHOD(GetColorSet)(DWORD dwDrawAspect,LONG lindex, void *pvAspect,
DVTARGETDEVICE *ptd, HDC hicTargetDev,
LOGPALETTE * *ppColorSet);
STDMETHOD(Freeze)(DWORD dwDrawAspect, LONG lindex,
void *pvAspect,DWORD *pdwFreeze);
STDMETHOD(Unfreeze)(DWORD dwFreeze);
STDMETHOD(SetAdvise)(DWORD aspects, DWORD advf, IAdviseSink *pAdvSink);
STDMETHOD(GetAdvise)(DWORD *pAspects, DWORD *pAdvf, IAdviseSink * *ppAdvSink);
STDMETHOD(GetExtent)(DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE __RPC_FAR *ptd, LPSIZEL lpsizel);
// IConnectionPointContainer methods
//
STDMETHOD(EnumConnectionPoints)(LPENUMCONNECTIONPOINTS FAR* ppEnum);
STDMETHOD(FindConnectionPoint)(REFIID iid, LPCONNECTIONPOINT FAR* ppCP);
// ISpecifyPropertyPages
//
STDMETHOD(GetPages)(CAUUID * pPages);
// IProvideClassInfo methods
//
STDMETHOD(GetClassInfo)(LPTYPEINFO * ppTI);
// constructor and destructor
//
COleControl(IUnknown *pUnkOuter, int iPrimaryDispatch, void *pMainInterface);
virtual ~COleControl();
// callable by anybody
//
static LRESULT CALLBACK ControlWindowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
static LRESULT CALLBACK ReflectWindowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
static COleControl * ControlFromHwnd(HWND hwnd) {
return (COleControl *) GetWindowLong(hwnd, GWL_USERDATA);
}
void __cdecl FireEvent(EVENTINFO * pEventInfo, ...);
HINSTANCE GetResourceHandle(void);
protected:
//=--------------------------------------------------------------------------=
// member variables that derived controls can get at.
//
// derived controls Should NOT modify the following.
//
IOleClientSite *m_pClientSite; // client site
IOleControlSite *m_pControlSite; // IOleControlSite ptr on client site
IOleInPlaceSite *m_pInPlaceSite; // IOleInPlaceSite for managing activation
IOleInPlaceFrame *m_pInPlaceFrame; // IOleInPlaceFrame ptr on client site
IOleInPlaceUIWindow *m_pInPlaceUIWindow; // for negotiating border space with client
ISimpleFrameSite *m_pSimpleFrameSite; // simple frame site
IDispatch *m_pDispAmbient; // ambient dispatch pointer
SIZEL m_Size; // the size of this control
HWND m_hwnd; // our window
HWND m_hwndParent; // our parent window
// flags indicating internal state. do not modify.
//
unsigned m_fDirty:1; // does the control need to be resaved?
unsigned m_fInPlaceActive:1; // are we in place active or not?
unsigned m_fInPlaceVisible:1; // we are in place visible or not?
unsigned m_fUIActive:1; // are we UI active or not.
unsigned m_fCreatingWindow:1; // indicates if we're in CreateWindowEx or not
unsigned short m_cAccel; // Size of accelerator table.
HACCEL m_hAccel; // Accelerator table.
// dervied controls can/should modify the following:
//
DWORD m_dwWindowStyle; // window flags for our HWND
DWORD m_dwWindowExStyle; // Window Style Extended Bits
LPSTR m_szWindowTitle; // title of the window.
//=--------------------------------------------------------------------------=
// methods that derived controls can override, but may need to be called
// from their versions.
//
virtual void ViewChanged(void);
virtual HRESULT InternalQueryInterface(REFIID riid, void **ppvObjOut);
//=--------------------------------------------------------------------------=
// member functions that derived controls will need to call from time to time
//
HRESULT DoSuperClassPaint(HDC, LPCRECTL);
HRESULT RecreateControlWindow(void);
BOOL DesignMode(void);
BOOL GetAmbientProperty(DISPID, VARTYPE, void *);
BOOL GetAmbientFont(IFont **ppFontOut);
void ModalDialog(BOOL fShow);
void InvalidateControl(LPCRECT prc);
BOOL SetControlSize(SIZEL *pSizel);
// IPropertyNotifySink stuff.
//
inline void PropertyChanged(DISPID dispid) {
m_cpPropNotify.DoOnChanged(dispid);
}
inline BOOL RequestPropertyEdit(DISPID dispid) {
return m_cpPropNotify.DoOnRequestEdit(dispid);
}
// subclassed windows controls support ...
//
inline HWND GetOuterWindow(void) {
return (m_hwndReflect) ? m_hwndReflect : m_hwnd;
}
private:
//=--------------------------------------------------------------------------=
// the following are methods that ALL control writers must override and implement
//
STDMETHOD(LoadBinaryState)(IStream *pStream) PURE;
STDMETHOD(SaveBinaryState)(IStream *pStream) PURE;
STDMETHOD(LoadTextState)(IPropertyBag *pPropertyBag, IErrorLog *pErrorLog) PURE;
STDMETHOD(SaveTextState)(IPropertyBag *pPropertyBag, BOOL fWriteDefault) PURE;
STDMETHOD(OnDraw)(HDC hdcDraw, LPCRECTL prcBounds, LPCRECTL prcWBounds, HDC hicTargetDev) PURE;
virtual LRESULT WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) PURE;
virtual BOOL RegisterClassData(void) PURE;
//=--------------------------------------------------------------------------=
// OVERRIDABLES -- methods controls can implement for customized functionality
//
virtual void AmbientPropertyChanged(DISPID dispid);
virtual void BeforeCreateWindow(void);
virtual void BeforeDestroyWindow(void);
virtual HRESULT DoCustomVerb(LONG lVerb);
virtual BOOL OnSetExtent(SIZEL *pSizeL);
virtual BOOL OnSpecialKey(LPMSG);
virtual BOOL OnGetPalette(HDC, LOGPALETTE **);
virtual BOOL InitializeNewState();
virtual void AfterCreateWindow(void);
//=--------------------------------------------------------------------------=
// methods that various people internally will share. not needed, however, by
// any inherting classes.
//
HRESULT InPlaceActivate(LONG lVerb);
void SetInPlaceVisible(BOOL);
void SetInPlaceParent(HWND);
HWND CreateInPlaceWindow(int x, int y);
HRESULT m_SaveToStream(IStream *pStream);
HRESULT LoadStandardState(IPropertyBag *pPropertyBag, IErrorLog *pErrorLog);
HRESULT LoadStandardState(IStream *pStream);
HRESULT SaveStandardState(IPropertyBag *pPropertyBag);
HRESULT SaveStandardState(IStream *pStream);
//=--------------------------------------------------------------------------=
// member variables we don't want anybody to get their hands on, including
// inheriting classes
//
HWND m_hwndReflect; // for subclassed windows
IOleAdviseHolder *m_pOleAdviseHolder; // IOleObject::Advise holder object
IAdviseSink *m_pViewAdviseSink; // IViewAdvise sink for IViewObject2
unsigned short m_nFreezeEvents; // count of freezes versus thaws
unsigned m_fHostReflects:1; // does the host reflect messages?
unsigned m_fCheckedReflecting:1; // have we checked above yet?
// internal flags. various other flags are visible to the end control class.
//
unsigned m_fModeFlagValid:1; // we stash the mode as much as possible
unsigned m_fSaveSucceeded:1; // did an IStorage save work correctly?
unsigned m_fViewAdvisePrimeFirst: 1; // for IViewobject2::setadvise
unsigned m_fViewAdviseOnlyOnce: 1; // for iviewobject2::setadvise
unsigned m_fUsingWindowRgn:1; // for SetObjectRects and clipping
VARIANT_BOOL m_fRunMode; // are we in run mode or not?
class CConnectionPoint : public IConnectionPoint {
public:
IUnknown **m_rgSinks;
// IUnknown methods
//
STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID FAR* ppvObj) ;
STDMETHOD_(ULONG,AddRef)(THIS) ;
STDMETHOD_(ULONG,Release)(THIS) ;
// IConnectionPoint methods
//
STDMETHOD(GetConnectionInterface)(IID FAR* pIID);
STDMETHOD(GetConnectionPointContainer)(IConnectionPointContainer FAR* FAR* ppCPC);
STDMETHOD(Advise)(LPUNKNOWN pUnkSink, DWORD FAR* pdwCookie);
STDMETHOD(Unadvise)(DWORD dwCookie);
STDMETHOD(EnumConnections)(LPENUMCONNECTIONS FAR* ppEnum);
void DoInvoke(DISPID dispid, DISPPARAMS * pdispparam);
void DoOnChanged(DISPID dispid);
BOOL DoOnRequestEdit(DISPID dispid);
COleControl *m_pOleControl();
CConnectionPoint(BYTE b){
m_bType = b;
m_rgSinks = NULL;
m_cSinks = 0;
}
~CConnectionPoint();
private:
BYTE m_bType;
int m_cSinks;
} m_cpEvents, m_cpPropNotify;
// so they can get at some of our protected things, like AddRef, QI, etc.
//
friend CConnectionPoint;
};
#define _CONTROLOBJECT_H_
#endif // _CONTROLOBJECT_H_